package com.application.sistercityapplication.model;

import java.util.Date;
import java.util.List;

import com.roscopeco.ormdroid.Entity;

public class Magazine extends Entity {
	public int id;
	public String title;
	public String path;
	public String cat;
	public String status;
	public String tumbnail;
	public String created_at;
	public String updeted_at;
	public String magId;
	public String countryId;
	public String catId;
	public String mouId;
	public String kmsId;
	
	

	public Magazine() {
		this(null, null, null, null, null, null, null, null, null, null, null, null);
	}

	public Magazine(String title, String path, String cat, String status, String tumbnail,  String created_at,String updeted_at
			,String magId, String countryId, String catId, String mouId, String kmsId) {
		this.title = title;
		this.cat = cat;
		this.path = path;
		this.status = status;
		this.tumbnail = tumbnail;
		this.magId = magId;
		this.countryId = countryId;
		this.catId = catId;
		this.mouId = mouId;
		this.kmsId = kmsId;
	}
	public void removeAll() {
		List<Magazine> list = query(Magazine.class).executeMulti();
		for (Magazine mag : list) {
			mag.delete();
		}
	}
	public int getPk(){
		List<Magazine> list = null;
		int key = 1;
		list = query(Magazine.class).executeMulti();
		if(list!=null && !list.isEmpty()){
			key = list.size()+1;
		}
		return key;
		
	}
	public boolean checkDuplicateData(String magId){
		boolean isUnDuplicate = true;
		List<Magazine> magList =  query(Magazine.class).where("magId").eq(magId).executeMulti();
		if(magList!=null && magList.size()>0){
			isUnDuplicate = false;
		}
		
		return isUnDuplicate;
	}
	public boolean checkDuplicateData(String magId,String cri){
		boolean isUnDuplicate = true;
		List<Magazine> magList =  query(Magazine.class).where(cri).eq(magId).executeMulti();
		if(magList!=null && magList.size()>0){
			isUnDuplicate = false;
		}
		
		return isUnDuplicate;
	}
	public List<Magazine> getAllByAuthen(boolean isAuthen){
		List<Magazine> list = null;
		list = query(Magazine.class).executeMulti();
		if(list!=null && list.size()>0){
			for(Magazine mag :list){
				if(!isAuthen){
					if("2".equals(mag.catId)){
						list.remove(mag);
					}
				}
			}
		}
		return list;
	}
}
